A.launch({
    readyEvent: 'ready'
});
$(window).on('agileready',function(){
	home_init();
});
function home_init(){
	main_init();
	asider_init('#area_asider');
}
function main_init(){

	var width=$(window).width();
	$('#slide').height(width/2)
    A.Slider('#slide', {
        dots : 'center',
        auto:3000
    });//得到一个slider组件（其类型为IScroll对象）
}
function asider_init(obj){
	$(obj).on('asideshow',function(){
		if($('.arealist li').length>0){
			return;
		}
		createVillageList();
	});
	$(obj).find('.titlebar .back').on('tap',function(){
		A.Aside.hide();
	})
}
function createVillageList(){

	var vaillagelist=AjaxPost('/interface/json_village',null,null,false);
	var obj=$('.arealist');
	$(obj).html('');
	var $ul=$('<ul></ul>');
	vaillagelist=SortByParm(vaillagelist,'firstLetter')
	$.each(vaillagelist, function(i, val) {
		var litter=val;
		var $li=$('<li></li>');
		$li.attr('id',litter.firstLetter);
		$li.append('<a class="title">'+litter.firstLetter+'</a><ul></ul>');
		var _$ul=$($li[0].lastChild);
		$.each(litter.list, function(j, _val) {
			var $vli=$('<li></li>');
			$vli.data('id',_val.villageID)
				.text(_val.villageName)
				.on('tap',function(event){
					setCurVillageById($(this).data('id'),this)
			});
			_$ul.append($vli);
		});
		$ul.append($li);
	});

	obj.append($ul);
	CreateLitterList(obj);
}
function setCurVillageById(id,obj){
	console.log(id);
}
function CreateLitterList(obj){

}
function SortByParm(list,parm){
	var _sub=new Object();
;
	for(var i=0;i<list.length-1;i++)
		for(var j=i+1;j<list.length;j++){
			if(list[i][parm]>list[j][parm]){
				_sub=list[i];
				list[i]=list[j];
				list[j]=_sub;
			}
		}
	return list;
}